import router from "@/router";
import { ElMessage } from 'element-plus'
class Util {
	constructor() {}
	toast(message, type = 'error', duration = 2000) {
		//type    success/warning/info/error
		ElMessage[type]({
			message,
			duration,
			grouping: true,
			showClose: true
		})
	}
	randomNumber() {
		let random = Math.random() + '';
		let randomStr = random.slice(2, random.length);
		console.log("获取16位随机数->", randomStr);
		return Number(randomStr)
	}
	checkLogin() {
		let path = router.currentRoute.path;
		let token = localStorage.getItem("token");
		if (token) {
			return true
		} else {
			if (path == '/login') {
				return
			}
			this.toast('暂未登录，请先登录', 'warning');
			setTimeout(() => {
				let payload = {
					name: "login",
					params: {
						path
					}
				}
				router.replace(payload);
			}, 1500)
			return
		}
	}
}
export default new Util();
